/*
 * @lc app=leetcode.cn id=1991 lang=typescript
 *
 * [1991] 找到数组的中间位置
 */

// @lc code=start
function findMiddleIndex(nums: number[]): number {
    let mid = 0;
    let left = 0;
    let right = nums.slice(1).reduce((col, cur) => {
        return col + cur;
    }, 0);
    while (left !== right && mid < nums.length) {
        left += nums[mid];
        right -= nums[mid + 1];
        mid++;
    }
    return mid >= nums.length ? -1 : mid;
}
// @lc code=end
